extends StaticBody2D


enum state {idle,attack}
var current_state
const attack = 100
var enemys = []
var elapsed_time = 0
var attack_time = 1
var current_enemy

func _ready():
	current_state = state.idle
	pass 

func _process(delta):
	if $ProgressBar.value <= 0:
		get_tree().paused = true
		get_tree().current_scene.get_node("WinPanel").show()
	elif current_state == state.attack:
		elapsed_time += delta
		if elapsed_time >= attack_time:
			if is_instance_valid(current_enemy):
				current_enemy.hurt(attack)
				elapsed_time = 0
	pass
	
func hurt(v):
	$ProgressBar.value -= v
	pass


func _on_EnemyJiance_body_entered(body):
	current_state = state.attack
	#current_enemy = body
	pass


func _on_EnemyJiance_area_entered(area):
	current_enemy = area
	current_state = state.attack
	print_debug("敌人进入")
	pass # Replace with function body.
